<template>
    <div class="goodinfo-container">
       <transition
       @before-enter="beforeEnter"
       @enter="enter"
       @after-enter="afterEnter"
       >
            <div class="ball" v-show="flag" ref="ball">
            </div>
       </transition>
        <!--  商品轮播图区域 -->
        <div class="mui-card">
				<div class="mui-card-content">
					<div class="mui-card-content-inner">
						<swiper :lunbolist="lunbo" :isfull="false"></swiper>
					</div>
				</div>
		</div>
        <!-- 商品购买区域 -->
        <div class="mui-card">
				<div class="mui-card-header">{{goodinfo.title}}</div>
				<div class="mui-card-content">
					<div class="mui-card-content-inner">
                        <p class="price">
                            市场价:<del>￥{{price}}</del>&nbsp;&nbsp;销售价:<span class="now">￥2199</span>
                        </p>
                        <p>
                            购买数量:<numbox @getcount="getSelectedCount" :max="kucun"></numbox>
                        </p>
                        <p>
                            <mt-button type="primary" size="small">立即购买</mt-button>
                            <mt-button type="danger" size="small" @click="addToShopCar">加入购物车</mt-button>
                        </p>
					</div>
				</div>
		</div>
        <!-- 商品参数区域 -->
        <div class="mui-card">
				<div class="mui-card-header">商品参数</div>
				<div class="mui-card-content">
					<div class="mui-card-content-inner">
                        <p>商品货号:{{ordernum}}</p>
                        <p>库存情况:{{kucun}}件</p>
                        <p>上架时间:{{goodinfo.createDate|dataFormat("YYYY年MM月DD日 HH:mm:ss")}}</p>
					</div>
				</div>
				<div class="mui-card-footer">
                    <mt-button type="primary" size="large" plain @click="getDesc(id)">图文介绍</mt-button>
                    <mt-button type="danger" size="large" plain @click="getComment(id)">商品评论</mt-button>
                </div>
		</div>
    </div>
</template>
<style lang="scss" scoped>
.goodinfo-container{
    .ball{
        width: 15px;
        height: 15px;
        border-radius: 50%;
        background-color: red;
        position: absolute;
        z-index: 99;
        top: 391px;
        left: 137px;
    }
    background-color: #eee;
    overflow: hidden;
    .now{
        color: red;
        font-size: 16px;
        font-weight: bold;
    }
    .mui-card-footer{
        display: block;
        button{
            margin: 15px 0;
        }
    }
}
</style>
<script>
import swiper from "../subcomponents/swiper.vue"
import numbox from "../subcomponents/goodinfonumbox.vue"
export default {
    data(){
        return {
            id:this.$route.params.id,
            lunbo:[],
            goodinfo:{},
            flag:false,
            selectedCount:1,
            kucun:50,
            price:2399
        }
    },
    created(){
        this.getlunbotu();
        this.getgoodinfo();
    },
    methods:{
        beforeEnter(el){
            el.style.transform="translate(0,0)"
        },
        enter(el,done){

            const ballpisition=this.$refs.ball.getBoundingClientRect();
            const badgeposition=document.getElementById("badge").getBoundingClientRect();
            const xmum=badgeposition.left-ballpisition.left;
            const ynum=badgeposition.top-ballpisition.top;
            el.offsetWidth;
            el.style.transform=`translate(${xmum}px,${ynum}px)`;
            el.style.transition="all 0.5s ease";
            done();
        },
        
        afterEnter(el){
            this.flag=!this.flag;
        },
        addToShopCar(){
            this.flag=!this.flag;
            var eachgood={
                id:this.id,
                count:this.selectedCount,
                price:this.price,
                title:this.goodinfo.title,
                selected:true
            }
            this.$store.commit("addgood",eachgood)
        },
        getlunbotu(){
            // this.$http.get("getlunbo").then(res=>{
            //     this.lunbo=res.body.data
            // })
            this.lunbo=[
                    "https://cdn.cnbj1.fds.api.mi-img.com/mi-mall/53641901fbc28cbcdb495b17fdf69e46.jpg?thumb=1&w=200&h=200&f=webp&q=90",
                    "https://m.360buyimg.com/mobilecms/jfs/t1/97208/6/6723/286631/5df825f6E37f2aa34/09d97b888100fd64.jpg!q70.jpg",
                    "https://m.360buyimg.com/mobilecms/jfs/t1/102962/5/6810/113002/5df75310E9a735577/794fed9928a58362.jpg!q70.jpg"
            ]
        },
        getgoodinfo(){
            this.$http.get("getEssayInfoById?id="+this.id).then(res=>{
                this.goodinfo=res.body.data
            })
        },
        getDesc(id){
            this.$router.push({
                name:"gooddesc",
                params:{
                    id
                }
            })
        },
        getComment(id){
            this.$router.push({
                name:"goodcomment",
                params:{
                    id
                }
            })
        },
        getSelectedCount(count){
            this.selectedCount=count;
        }
    },
    components:{
        swiper,
        numbox
    },
    computed:{
        ordernum(){
            var result=this.id.substring(0,15)
            return result;
        }
    }
}
</script>